// 公共模块：连接数据库

import { Global, Module } from '@nestjs/common';
import { TypegooseModule } from 'nestjs-typegoose';
import { DbService } from './db.service';

import { Slide } from './models/slide.model';
import { User } from './models/user.model';
import { Article } from './models/article.model';
import { Equip } from './models/equip.model';
import { Hero } from './models/hero.model';

// 导入集合，然后到 Module 中导入，因为 Module 是全局的，所以他也变成全局的了
const models = TypegooseModule.forFeature([
  User,
  Slide,
  Article,
  Equip,
  Hero
])

@Global()  // 修饰为 全局的
@Module({
  imports: [
    TypegooseModule.forRoot('mongodb://localhost/nest-mtbx', {
      useNewUrlParser: true,
      useUnifiedTopology: true,
      useCreateIndex: true,
      useFindAndModify: false,
    }),
    models
  ],
  providers: [DbService],
  exports: [DbService, models],
})
export class DbModule {}
